//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.GpsStatus.Listener;
import android.os.Bundle;
import com.baidu.trace.a.g;

public final class ak implements LocationListener {
    private LocationManager b;
    private Location c;
    private boolean d;
    private int e = 0;
    private int f = 10;
    protected static int a = -1;
    private long g = 0L;
    private Context h;
    private ak.a i;
    private final Listener j = new al(this);

    public ak(Context var1) {
        this.h = var1;
        ak var4 = this;

        try {
            var4.b = (LocationManager)var4.h.getSystemService("location");
            if(var4.b != null && null != var4.b.getAllProviders() && var4.b.getAllProviders().contains("gps")) {
                var4.b.addGpsStatusListener(var4.j);
                var4.b.sendExtraCommand("gps", "force_xtra_injection", new Bundle());
            } else {
                var4.b = null;
            }
        } catch (SecurityException var2) {
            ;
        } catch (Exception var3) {
            this.b = null;
        }

        this.i = new ak.a();
    }

    protected final void a() {
        if(this.b != null) {
            this.b.removeUpdates(this);
        }

        a = -1;
    }

    protected final void a(g var1, int var2) {
        if(this.i != null && System.currentTimeMillis() - this.g < (long)var2) {
            var1.c = Integer.valueOf(this.e != 0?this.e:1).byteValue();
            var1.d = Integer.valueOf(this.i.b).shortValue();
            var1.g = Integer.valueOf(this.i.e).shortValue();
            var1.e = Integer.valueOf(this.i.c).byteValue();
            var1.i = this.i.g;
            var1.h = this.i.f;
            var1.f = Integer.valueOf(this.i.d).shortValue();
            var1.a = var1.c > 0 && var1.i != 0 && var1.h != 0;
            var1.b = this.i.a;
            com.baidu.trace.a.a("G-GPS local time is: " + this.i.a);
            if(a != 0) {
                this.a(0, "已通过GPS定位");
                return;
            }
        } else {
            var1.a = false;
            if(1 != a) {
                this.a(1, "正在搜索GPS");
            }
        }

    }

    protected final boolean a(int var1) {
        if(this.b == null) {
            return false;
        } else {
            this.d = this.b.isProviderEnabled("gps");
            if(!this.d) {
                if(2 != a) {
                    this.a(2, "已关闭GPS");
                }

                return false;
            } else {
                int var2 = var1;
                ak var4 = this;

                try {
                    if(var4.c == null) {
                        var4.c = var4.b.getLastKnownLocation("gps") != null?var4.b.getLastKnownLocation("gps"):new Location("gps");
                    }

                    var4.b.addGpsStatusListener(var4.j);
                    var4.b.requestLocationUpdates(var4.c.getProvider(), (long)var2, (float)var4.f, var4);
                } catch (Exception var3) {
                    ;
                }

                if(this.c != null) {
                    return true;
                } else {
                    if(1 != a) {
                        this.a(1, "正在搜索GPS");
                    }

                    return false;
                }
            }
        }
    }

    public final void onLocationChanged(Location var1) {
        this.g = System.currentTimeMillis();
        if(var1 != null) {
            Location var4 = this.c;
            boolean var12;
            if(var4 == null) {
                var12 = true;
            } else {
                long var5;
                boolean var2 = (var5 = var1.getTime() - var4.getTime()) > 120000L;
                boolean var7 = var5 < -120000L;
                boolean var11 = var5 > 0L;
                if(var2) {
                    var12 = true;
                } else {
                    label93: {
                        if(!var7) {
                            int var8;
                            boolean var6 = (var8 = (int)(var1.getAccuracy() - var4.getAccuracy())) > 0;
                            var7 = var8 < 0;
                            var2 = var8 > 200;
                            String var10000 = var1.getProvider();
                            String var10 = var4.getProvider();
                            String var3 = var10000;
                            boolean var9 = var10000 == null?var10 == null:var3.equals(var10);
                            if(var7) {
                                var12 = true;
                                break label93;
                            }

                            if(var11 && !var6) {
                                var12 = true;
                                break label93;
                            }

                            if(var11 && !var2 && var9) {
                                var12 = true;
                                break label93;
                            }
                        }

                        var12 = false;
                    }
                }
            }

            if(var12) {
                this.c = var1;
                if(this.i == null) {
                    this.i = new ak.a();
                }

                this.i.a = this.c.getTime();
                this.i.b = (int)this.c.getAccuracy();
                this.i.c = (int)(this.c.getBearing() / 2.0F);
                this.i.d = (int)(this.c.getSpeed() * 360.0F);
                this.i.e = (int)this.c.getAltitude();
                this.i.f = (int)(this.c.getLongitude() * 600000.0D);
                this.i.g = (int)(this.c.getLatitude() * 600000.0D);
            }
        }

    }

    public final void onProviderDisabled(String var1) {
    }

    public final void onProviderEnabled(String var1) {
    }

    public final void onStatusChanged(String var1, int var2, Bundle var3) {
    }

    protected final void a(int var1, String var2) {
        a = var1;
        Intent var3;
        (var3 = new Intent("com.baidu.trace.action.GPS_STATUS")).putExtra("statusCode", var1);
        var3.putExtra("statusMessage", var2);
        this.h.sendBroadcast(var3);
    }

    public class a {
        long a;
        int b;
        int c;
        int d;
        int e;
        int f;
        int g;

        protected a() {
        }
    }
}
